﻿using System;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.Collections.Generic;

namespace ThePresenter.Polls.Data
{
	[Serializable]
	public class SelectOptionsData : OptionsData, ISerializable
	{
		#region Fields
		/// <summary>
		/// Value indicating whether this instance is single choice.
		/// </summary>
		/*readonly?*/ bool _IsSingleChoice;

		/// <summary>
		/// The options.
		/// </summary>
		List<string> _Options;
		#endregion


		#region Properties
		/// <summary>
		/// Gets or sets a value indicating whether this instance is single choice.
		/// </summary>
		/// <value><c>true</c> if this instance is single choice; otherwise, <c>false</c>.</value>
		public bool IsSingleChoice
		{
			get
			{
				return _IsSingleChoice;
			}
			set
			{
				if (value != _IsSingleChoice)
				{
					_IsSingleChoice = value;
					OnPropertyChanged("IsSingleChoice");
				}
			}
		}

		/// <summary>
		/// Gets or sets the options.
		/// </summary>
		/// <value>The options.</value>
		public List<string> Options
		{
			get
			{
				if (_Options == null)
				{
					_Options = new List<string>();
					//_Options.CollectionChanged += new NotifyCollectionChangedEventHandler((s, e) => this.OnPropertyChanged("Options"));
				}

				return _Options;
			}
			set
			{
				if (value != Options)
				{
					_Options = value;
					OnPropertyChanged("Options");
				}
			}
		}
		#endregion


		#region Constructors
		/// <summary>
		/// Initializes a new instance of the <see cref="SelectOptionsData"/> class.
		/// </summary>
		public SelectOptionsData()
		{
		}
		#endregion


		#region ISerializable Members
		/// <summary>
		/// Initializes a new instance of the <see cref="Poll"/> class.
		/// </summary>
		/// <param name="info">The info.</param>
		/// <param name="context">The context.</param>
		public SelectOptionsData(SerializationInfo info, StreamingContext context)
		{
			_IsSingleChoice = (bool)info.GetValue("SingleChoice", typeof(bool));
			_Options = new List<string>((string[])info.GetValue("Options", typeof(string[])));
			OptionsType = (OptionsType)info.GetValue("OptionsType", typeof(OptionsType));
		}

		/// <summary>
		/// Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with the data needed to serialize the target object.
		/// </summary>
		/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> to populate with data.</param>
		/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext"/>) for this serialization.</param>
		/// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission. </exception>
		public void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("SingleChoice", _IsSingleChoice, typeof(bool));
			info.AddValue("Options", _Options.ToArray(), typeof(string[]));
			info.AddValue("OptionsType", OptionsType, typeof(OptionsType));
		}
		#endregion

	}
}
